package com.ruoyi.asset.lamp.controller;


import cn.dev33.satoken.annotation.SaIgnore;
import com.ruoyi.asset.lamp.domain.bo.*;
import com.ruoyi.asset.lamp.domain.vo.LampMaintenanceVo;
import com.ruoyi.asset.lamp.service.ILampMaintenanceService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.standingbook.lamp.service.ILampService;
import com.ruoyi.system.domain.vo.SysOssVo;
import com.ruoyi.system.service.ISysDictDataService;
import com.ruoyi.system.service.ISysOssService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * 灯光管养
 *
 * @author 12276
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/asset/lamp")
public class LampMaintenanceController extends BaseController {

    private final ILampMaintenanceService lampMaintenanceService;
    private final ILampService lampService;
    private ISysDictDataService sysDictDataService= SpringUtils.getBean(ISysDictDataService.class);

    /**
     * 获取灯光管养-管理范围导入模板
     */
    @SaIgnore()
    @Log(title = "灯光管养管理范围导入", businessType = BusinessType.IMPORT)
    @RepeatSubmit()
    @PostMapping(value = "/importData")
    public R<List<String>> importData(@RequestParam(name = "excelUrl") String excelUrl) {
        List<String> list = this.lampMaintenanceService.importExcel(excelUrl);

        if (list == null) {
            return R.fail();
        } else {
            return R.ok(list);
        }
    }

    /**
     * 获取灯光管养-管理范围导入模板
     */
    @SaIgnore()
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) {
        ExcelUtil.exportExcel(new ArrayList<>(), "灯光管养管理范围导入模板", LampMaintenanceVo.class, response);
    }

    /**
     * 删除路灯管养范围
     */
    @SaIgnore()
    @DeleteMapping("/deleteLampMaintenance/{ids}")
    public R<Void> deleteLampMaintenance(@NotEmpty(message = "主键不能为空")
                                         @PathVariable Set<Long> ids) {
        int count = this.lampMaintenanceService.deleteLampMaintenance(ids);

        return toAjax(count >= 0 ? 1 : count);
    }

    /**
     * 查询路灯管养范围
     */
    @SaIgnore()
    @GetMapping("/queryLampMaintenance")
    public TableDataInfo<LampMaintenanceVo> queryLampMaintenance(LampMaintenanceBo searchBo, PageQuery pageQuery) {
        return this.lampMaintenanceService.queryLampMaintenance(searchBo, pageQuery);
    }

    /**
     * 导出路灯管养范围
     */
    @SaIgnore()
    @Log(title = "路灯管养范围导出", businessType = BusinessType.EXPORT)
    @PostMapping("/exportLampMaintenance")
    public void exportLampMaintenance(LampMaintenanceBo searchBo, HttpServletResponse response) {
        List<LampMaintenanceVo> list = this.lampMaintenanceService.queryLampMaintenance(searchBo);

        ExcelUtil.exportExcel(list, "路灯管养范围", LampMaintenanceVo.class, response);
    }

    @SaIgnore()
    @GetMapping("/lampCount")
    public R<LampMaintenanceStatisticsBo> lampCount() {
        LampMaintenanceStatisticsBo lampCount = lampMaintenanceService.getLampCount();
        return R.ok(lampCount);
    }

    @SaIgnore()
    @GetMapping("/lampCommunityCount")
    public R<Map> lampCommunityCount() {
        Map map = lampMaintenanceService.getLampCommunityCount();
        return R.ok(map);
    }

    /**
     * 查询智慧大屏路灯管养玉塘街道全社区
     * @param date
     * @return
     */
    @SaIgnore()
    @GetMapping("/lampCommunity")
    public R<List<LampCommunityCountBo>> lampCommunity(String date) {
        date = "2024-03-13";
        List<LampCommunityCountBo> lampCountByCommunity = lampMaintenanceService.getLampCountByCommunity(date);
        return R.ok(lampCountByCommunity);
    }

    /**
     * 查询智慧大屏路灯管养今日作业统计与百分比
     * @param date
     * @return
     */
    @SaIgnore()
    @GetMapping("/lampWorkByDate")
    public R<LampWorkStatisticsBo> lampWorkByDate(String date) {
        date = "2024-03-13";
        LampWorkStatisticsBo lampWorkByDate = lampMaintenanceService.getLampWorkByDate(date);
        return R.ok(lampWorkByDate);
    }

    /**
     * 查询智慧大屏路灯管养今日作业统计与百分比 指定社区
     * @param date
     * @return
     */
    @SaIgnore()
    @GetMapping("/lampWorkByDateAndCommunity")
    public R<LampWorkStatisticsBo> lampWorkByDateAndCommunity(String date,String community) {
        date = "2024-03-13";
        LampWorkStatisticsBo lampWorkByDate = lampMaintenanceService.getLampWorkByDateAndCommunity(date,community);
        return R.ok(lampWorkByDate);
    }

    /**
     * 查询智慧大屏路灯管养按社区区分
     * @param community
     * @param date
     * @return
     */
    @SaIgnore()
    @GetMapping("/communityByDate")
    public R<LampCommunityMapBo> communityByDate(String community, String date) {
        date = "2024-03-13";
        LampCommunityMapBo communityByDate = lampMaintenanceService.getCommunityByDate(community, date);
        return R.ok(communityByDate);
    }

}
